<?
include("/var/www/html/new/conf/r.le.je");
$le=new go_sql();
$le->connect(); 

include("/var/www/html/new/com.inc.php");

if (!class_exists("cpaint")){
  include("/var/www/html/new/cpaint/cpaint2.inc.php");
  $cp=new cpaint();
}
//mail check
function mailreg($email) {
	$node=$GLOBALS['cp']->add_node("emailn");
	$alertmail="";
	$email=strtolower($email);
	if(!preg_match('/^\w+@([0-9]|[a-z]|[0-9a-z])+\.*([a-z]|[0-9]|[0-9a-z])+\.[a-z]{2,4}$/',$email)){
		$alertmail.="0 | <img src='/images/3.png' class='imgie6' align='absmiddle' />&nbsp;<font color=red>邮件格式错误</font>";
	}else{
	  $str="select did,act from uu_member where email=\"".$email."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $act=$GLOBALS['le']->f("act");
	  $str="select did from uu_temp_member where date_add(mod_time,  interval 30 minute)>now() and email=\"".$email."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did2=$GLOBALS['le']->f("did");
	  
	 if (!$did && !$did2){
	 $alertmail.="1 | <img src='/images/1.png' class='imgie6' align='absmiddle' />&nbsp;邮箱可以注册"; 	
	 }else{
		 if($act=='1'){
	 $alertmail.="0 | <img src='/images/3.png' class='imgie6' align='absmiddle' />&nbsp;<font color=red>email地址已被使用，请更换</font>"; 
		 }else{
	 $alertmail.="0 | <img src='/images/3.png' class='imgie6' align='absmiddle' />&nbsp;<font color=#A3162D>此邮箱已申请注册过，</font><a href='javascript:void[0]' onmouseup='re_send_check_mail()'><span style='text-decoration:underline; font-size:14px; color:red'>点击重发验证邮件</a></span>"; 	 
		 }
	 }
	}
	$node->set_data($alertmail);
    return;	
}

//pwd check
function pwdreg($pwd1,$pwd2) {
  $node=$GLOBALS['cp']->add_node("preg");
  $alertpwd="";
  
  if (!$pwd1) {
  $alertpwd.= "0 | <img src=images/3.png align=absmiddle class=imgie6 />&nbsp;<font color=red>密码不能为空</font>";
   if ($pwd2) $alertpwd.="|0|0|<img src=images/2.png align=absmiddle class=imgie6 />&nbsp;<font color=red>第一次输入密码有误</font>";
   $node->set_data($alertpwd);
   return;
  } 
  
  if (p_match($pwd1)) {
   $alertpwd.= "0 | <img src='/images/3.png' align='absmiddle' class=imgie6 />&nbsp;<font color=red>密码含有非法字符</font>";
   if ($pwd2) $alertpwd.="|0|0|<img src=images/2.png align=absmiddle class=imgie6 />&nbsp;<font color=red>第一次输入密码有误</font>";
   $node->set_data($alertpwd);
   return;
  } 

    $pwdlen=mb_strlen($pwd1,"utf-8");


   $strength = 0;
   //$str_strength=0;
   // 小写字母
   if(preg_match("/([a-z]+)/", $pwd1)) {
    $strength++;
   }
   // 大写字母
   if(preg_match("/([A-Z]+)/", $pwd1)) {
       $strength++;
   }
   // 数字
   if(preg_match("/([0-9]+)/", $pwd1)) {
       $strength++;
   }
   // 非任意(文字和数字)字母和下滑线的字符
   if(preg_match("/(\W+)/", $pwd1)) {
       $strength++;
   }
   // 密码的长度
   if (strlen($pwd1) < 8) $strength--;
   else $strength++;
   switch($strength) {
       case 0:
       case 1:
          $str_strength=1;
       break;
       case 2:
       case 3:
          $str_strength=2;
       break;
       case 4:
       case 5:
          $str_strength=3;
       break;
	   default:$str_strength=1;
   }




	
  if($pwdlen<6 or $pwdlen>20) {
	$alertpwd.="0 | <img src='/images/2.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>密码不能少于6位或大于20位</font>"; 
	if ($pwd2) $alertpwd.="|0|0|<img src=images/2.png align=absmiddle class=imgie6 />&nbsp;<font color=red>第一次输入密码有误</font>";
    $node->set_data($alertpwd);
   return;	
  }else{
    $alertpwd.="1 | <img src='/images/1.png' class=imgie6 align='absmiddle'/>&nbsp;密码格式正确 |".$str_strength;
  }

if ($pwd2) {
	$alertpwd.=" | ";
if ($pwd1<>$pwd2) {
	$alertpwd.="0 | <img src='/images/2.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>密码前后不一样，请修改</font>"; 
   } else {
	$alertpwd.="1 | <img src='/images/1.png' class=imgie6 align='absmiddle'/>&nbsp;密码前后已匹配";
   }

}

    $node->set_data($alertpwd);
   return;	
}

//checks check
function checkscheck($checks) {
	$node=$GLOBALS['cp']->add_node("checksn");
	$alertcheck="";
	if (strtolower($_SESSION[checkWordReg])==strtolower($checks)) {
		$alertcheck.="1 | <img src='/images/1.png' class=imgie6 align='absmiddle'/>&nbsp;验证码填写正确";
	}else{
		$alertcheck.="0 | <img src='/images/2.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>验证码错误，请重填</font>";
	}
		$node->set_data($alertcheck);
   return;	
}

function reg_now_ajax($duser, $pwd1, $pwd2, $checks, $code, $n){
	$node=$GLOBALS['cp']->add_node("reg_now_ajax_n");
	$dtext="";

if ($n==1){
$email=$duser;	
$email=strtolower($email);
	if(!preg_match('/^\w+@([0-9]|[a-z]|[0-9a-z])+\.*([a-z]|[0-9]|[0-9a-z])+\.[a-z]{2,4}$/',$email)){
		$dtext.="0 | 邮件格式错误，请重填！";
		$node->set_data($dtext);
        return;	
	}
	
	  $str="select did,act from uu_member where email=\"".$email."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $act=$GLOBALS['le']->f("act");
	  
	 if ($did){
		 if ($act=='0'){
	       $dtext.="0 | 此email地址正在等待验证，无法现在注册！\n请到邮箱去收取邮件或重发验证邮件！";
		 }else{
	       $dtext.="0 | email地址已被使用，请更换！";
		 }
		   $node->set_data($dtext);
           return;				 
	  }

if (strtolower($_SESSION[checkWordReg])!=strtolower($checks)) {
	$dtext.="0 | 验证码错误，请重填！";
	$node->set_data($dtext);
    return;		
}
	  
}else{
$tel=$duser;

if(!preg_match('/^1(3|5|8)\d{9}$/ ',$tel)){
	$dtext.="0 | 请输入正确的手机号码";
	$node->set_data($dtext);
    return;		
}

	  $str="select did from uu_member where mobile=\"".$tel."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  
if ($did) {
	$dtext.="0 | 手机号已被使用，请更换";
	$node->set_data($dtext);
    return;
}

/*
if (!$code){
	$dtext.="0 | 短信验证码不能为空！";
	$node->set_data($dtext);
    return;		
}

if (p_match($code)){
	$dtext.="0 | 短信验证码中含有非法字符！";
	$node->set_data($dtext);
    return;	
}

if ($_SESSION["sms_tel_randc"]!=$tel) {
	$dtext.="0 | 此手机号码需要重新获取验证码！";
	$node->set_data($dtext);
    return;
}

if ($_SESSION["sms_yzm_randc"]!=$code) {
	$dtext.="0 | 手机验证码不对！";
	$node->set_data($dtext);
    return;
}*/
	
}

	if (p_match($pwd1) || p_match($pwd2)) {
	$dtext.="0 | 密码中含有非法字符，注册失败！";
	$node->set_data($dtext);
    return;
	}
	
	if ($pwd1!=$pwd2) {
	$dtext.="0 | 密码前后不相等，注册失败！";
	$node->set_data($dtext);
    return;		
	}
    $pwdlen=mb_strlen($pwd1,"utf-8");	
	if($pwdlen<6 or $pwdlen>20) {
	$dtext.="0 | 密码不能少于6位或大于20位！";
	$node->set_data($dtext);
    return;		
	}	

//检测通过
$pp=$_SERVER['REQUEST_TIME'];
$pp1=substr($pp,0,5);
$pp2=substr($pp,5,5);
$zf="ABCDEFGHJKT";
$zf_n=rand(0,9);
$pp="X".$pp1.$zf{$zf_n}.$pp2;
$pw=md5(md5($pwd1));

if ($n==1){
$host=$_SERVER['HTTP_HOST'];

$str="insert uu_member set passport='$pp',password='$pw',email='$email',create_time=now()";
if (!$GLOBALS['le']->query($str)){
	$dtext.="0 | 网络连接失败！稍后再试！";
	$node->set_data($dtext);
    return;		
}
//发送邮件
require_once("../mail_t/mail.php");
$iden=md5($email).md5($pw);
$res=mailt($email,"先行网账号验证激活邮件",$host.",".$iden,"localhost,identify");
if ($res!=1){
	$dtext.=$res;
	$node->set_data($dtext);
    return;		
}
    $dtext="1 | 系统已经向您的邮箱发送一封邮件，您必须登录邮箱激活后，账户才能使用！";
	$node->set_data($dtext);
    return;	
}else{
$str="insert uu_member set passport='$pp',password='$pw',mobile='$tel',act='1',create_time=now()";
if (!$GLOBALS['le']->query($str)){
	$dtext.="0 | 网络连接失败！稍后再试！";
}else{
	  $str="select did,passport from uu_member where mobile=\"".$tel."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $passport=$GLOBALS['le']->f("passport");
	  $did=$GLOBALS['le']->f("did");
	
 	require_once("../tel/tel.php");
	$_w['sms_pw']="31cfc170f70535b0d4dc92363c486de8";
	
	$sendmsg="您的账号为手机号，";
	$sendmsg.="密码为：".$pwd1."，";
	$sendmsg.="先行网www.16u.com（一路游，好风景）感谢您的注册！";
    $url="http://gateway.woxp.cn:6630/utf8/web_api/?x_eid=10286&x_uid=Denny&x_pwd_md5=".$_w['sms_pw']."&x_ac=10&x_gate_id=300&x_target_no=".$tel."&x_memo=".$sendmsg; 
	$num=Get($url);
    if ($num<=0){
	 $dtext.="1 | 注册成功！短信发送失败：".telcode($num).$num;  
	}else{
	$dtext.="1 | 注册成功！系统已将密码发到您的手机！\n密码经过加密，除了您任何人都无法获取，丢失了只能到我们网站重置，请妥善保存。";
	}
	$_SESSION["uu_user"]=$tel;
	$_SESSION["uu_id"]=$did;
}
	$node->set_data($dtext);
    return;		
}
}

function re_send_check_mail_ajax($email) {
	$node=$GLOBALS['cp']->add_node("re_send_check_mail_ajaxn");
	$alertmail="";
	if(!preg_match('/^\w+@([0-9]|[a-z]|[0-9a-z])+\.*([a-z]|[0-9]|[0-9a-z])+\.[a-z]{2,4}$/',$email)){
		$alertmail.="0 | 邮件格式错误";
	}else{
	  $str="select did,act,password from uu_member where email=\"".$email."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $act=$GLOBALS['le']->f("act");
	  $pw=$GLOBALS['le']->f("password");
	  	  
	 if (!$did){
	 $alertmail.="0 | 找不到此email地址！"; 
	 }else{
		 if($act){
	 $alertmail.="0 | email地址已被激活，你不用重复验证！"; 
		 }else{

require_once("../mail_t/mail.php");
	$iden=md5($email).md5($pw);
	$host=$_SERVER['HTTP_HOST'];
	$res=mailt($email,"先行网账号验证激活邮件",$host.",".$iden,"localhost,identify");
if ($res!=1){
	$dtext=$res;
	$node->set_data($dtext);
    return;		
}
			 
	 $alertmail.="1 | 系统已重新发送一份验证邮件到您的邮箱！请查收！ "; 	 
		 }
	 }
	}
	$node->set_data($alertmail);
    return;	
}

//tel check
function checktel_ajax($tel) {
	$node=$GLOBALS['cp']->add_node("checktel_ajaxn");
	$alerttel="";
	
	if(!preg_match('/^1(3|5|8)\d{9}$/ ',$tel)){
	$alerttel.="0 | <img src='/images/3.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>不是一个完整的手机号码</font>";
	}else{
	  $str="select did from uu_member where mobile=\"".$tel."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");	

	 if (!$did){
		if ($_SESSION["sms_tel_randc"]!=$tel){ 
	 $alerttel.="1 | <img src='/images/1.png' class=imgie6 align='absmiddle'/>&nbsp;手机号可以使用"; 
		}else{
	 $alerttel.="1 | <img src='/images/1.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=gray>此手机号验证码已发送！</font></a>"; 			
		}
	 }else{
	 $alerttel.="0 | <img src='/images/3.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>手机号已被使用，请更换</font>"; 
	 }
	}
	
	    $node->set_data($alerttel);
   return;	
}

//get_yzm_ajax
function get_yzm_ajax($tel) {
	$node=$GLOBALS['cp']->add_node("get_yzm_ajaxn");
	$alerttel="";
	if(!preg_match('/^1(3|5|8)\d{9}$/ ',$tel)){
	$alerttel.="0 | 请输入正确的手机号码,以便获取验证码";
	}else{
	  $str="select did from uu_member where mobile=\"".$tel."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");	

	 if (!$did){
 	require_once("../tel/tel.php");
	$_w['sms_pw']="31cfc170f70535b0d4dc92363c486de8";
	$randc=rand(100000,999999);
	$sendmsg="先行网www.16u.com（一路游，好风景）用户注册验证码，如果不是您本人申请的，对您的打扰感到万分抱歉。";
	$sendmsg.="您的验证码是：".$randc;
    $url="http://gateway.woxp.cn:6630/utf8/web_api/?x_eid=10286&x_uid=Denny&x_pwd_md5=".$_w['sms_pw']."&x_ac=10&x_gate_id=300&x_target_no=".$tel."&x_memo=".$sendmsg; 
	$num=Get($url);
    if ($num<=0){
	 $alerttel.="0 | ".telcode($num).$num;  
	}else{
	$alerttel.="1 | 短信发送成功。\n可能需要1-10分钟，您才能收到验证码，请您耐心等候！";
	$_SESSION["sms_yzm_randc"]=$randc;
	$_SESSION["sms_tel_randc"]=$tel;
	}
	 }else{
	 $alerttel.="0 | 手机号已被使用，请更换"; 
	 }
	}
	
	    $node->set_data($alerttel);
   return;	
}

function forget_pw_ajax($yzm){
	$node=$GLOBALS['cp']->add_node("forget_pw_ajax_n");	
	$dtext="";

if (p_match($yzm)){
	$dtext.="0 | 短信验证码含有非法字符！";
	$node->set_data($dtext);
    return;	
}

if ($yzm != $_SESSION["pw_cz_randc"]){
	$dtext.="0 | 短信验证码错误！";
	$node->set_data($dtext);
    return;	
}

	  $str="select did,unix_timestamp(cz_time) as ctime from uu_member where mobile=\"".$_SESSION["tel_cz_randc"]."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $ctime=$GLOBALS['le']->f("ctime");
	  $now=$_SERVER['REQUEST_TIME'];
	  if ($did){
		  if (($now-$ctime)<600){
			  $dtext.="0 | 10分钟内只能重置1次密码。\n请您稍后再来尝试！";
	          $node->set_data($dtext);
              return;
		  }elseif($cz>100){
			  $dtext.="0 | 已超过密码重置次数，不能重置！";
	          $node->set_data($dtext);
              return;	
		  }else{

 	require_once("../tel/tel.php");
	$_w['sms_pw']="31cfc170f70535b0d4dc92363c486de8";
	$randc=rand(100000,999999);
	//$sendmsg=$_SESSION["tmp_name"]."，您好！";
	$sendmsg="您的先行网www.16u.com（一路游，好风景）密码已被重置为：".$randc."。";
	$sendmsg.="请您尽快登录更换为自己的密码！";

    $url="http://gateway.woxp.cn:6630/utf8/web_api/?x_eid=10286&x_uid=Denny&x_pwd_md5=".$_w['sms_pw']."&x_ac=10&x_gate_id=300&x_target_no=".$_SESSION["tel_cz_randc"]."&x_memo=".$sendmsg; 
	$num=Get($url);
    if ($num<=0){
	 $dtext.="0 | ".telcode($num).$num;  
	}else{
	  $str="update uu_member set cz=cz+1,cz_time=now(),password=md5(md5('".$randc."')) where mobile=\"".$_SESSION["tel_cz_randc"]."\"";
      $GLOBALS['le']->query($str);	
	
	$dtext.="1 | 密码重置成功。|".$randc;
    session_destroy();	
	}
		  }
	  }
	  

	$node->set_data($dtext);
    return;		
}

function m_tel_third_ajax($yzm){
	$node=$GLOBALS['cp']->add_node("m_tel_third_ajax_n");	
	$dtext="";

if (!$_SESSION["uu_id"]){
	$dtext.="0 | 对不起，你的登录已失效，请刷新页面！";
	$node->set_data($dtext);
    return;	
}

if (p_match($yzm)){
	$dtext.="0 | 短信验证码含有非法字符！";
	$node->set_data($dtext);
    return;	
}

if ($yzm != $_SESSION["m_tel_randc"]){
	$dtext.="0 | 短信验证码错误！";
	$node->set_data($dtext);
    return;	
}

	  $str="select did,act,jz from uu_member where did='".$_SESSION["uu_id"]."'";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $act=$GLOBALS['le']->f("act");
      $jz=$GLOBALS['le']->f("jz");

	  if ($did){
		  if ($act!='1'){
			  $dtext.="0 | 对不起您的账户还未激活，无法进行操作！";
	          $node->set_data($dtext);
              return;
		  }elseif($jz=='1'){
			  $dtext.="0 | 对不起您的账户已被禁止登录，无法绑定手机！";
	          $node->set_data($dtext);
              return;	
		  }else{
 		  $str="update uu_member set mobile='".$_SESSION["mod_tel"]."' where did='".$_SESSION["uu_id"]."'";
          $GLOBALS['le']->query($str);	
	      $dtext.="1 | 绑定新手机号成功。您可以用新手机号做为用户名登录！";
		  }
	  }
	  
	$node->set_data($dtext);
    return;		
}

function chkTrueName_ajax($tname){
	$node=$GLOBALS['cp']->add_node("chkTrueName_ajax_n");	
	$dtext="";

if (p_match($tname)){
	$dtext.="0 | 用户名含有非法字符！";
	$node->set_data($dtext);
    return;	
}

	  $str="select did,cz,unix_timestamp(cz_time) as ctime from uu_member where uname=\"".$tname."\" limit 1";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $cz=$GLOBALS['le']->f("cz");
	  $ctime=$GLOBALS['le']->f("ctime");
	  $now=$_SERVER['REQUEST_TIME'];
	  if ($did){
		  if (($now-$ctime)<600){
			  $dtext.="0 | 10分钟内只能重置1次密码。\n请您稍后再来尝试！";
	          $node->set_data($dtext);
              return;
		  }elseif($cz>100){
			  $dtext.="0 | 已超过密码重置次数，不能重置！";
	          $node->set_data($dtext);
              return;			  
			  
		  }else{
			  $_SESSION["tmp_name"]=$tname;
			  $dtext.="1 |".$tname;
	          $node->set_data($dtext);
              return;				  	  
		  }
	  }else{
		$dtext.="0 | 找不到此姓名的任何相关记录。\n请换个名字重试！";
	    $node->set_data($dtext);
        return;			  
	  }

	$node->set_data($dtext);
    return;		
}

function m_tel_first_ajax($pwd, $num){
	$node=$GLOBALS['cp']->add_node("m_tel_first_ajax_n");	
	$dtext="";

if (p_match($pwd)){
	$dtext.="0 | 密码含有非法字符！";
	$node->set_data($dtext);
    return;	
}

	  $str="select did from uu_member where did=\"".$_SESSION['uu_id']."\" and password=md5(md5('".$pwd."'))";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");

	  if ($did){
		$dtext.="1 |".$num;
	    $node->set_data($dtext);
        return;				  	  
	  }else{
		$dtext.="0 | 密码错误！";
	    $node->set_data($dtext);
        return;			  
	  }

	$node->set_data($dtext);
    return;		
}

function get_pw_sms_ajax($tel){
	$node=$GLOBALS['cp']->add_node("get_pw_sms_ajax_n");	
	$dtext="";

if(!preg_match('/^1(3|5|8)\d{9}$/ ',$tel)){
	$dtext.="0 | 请输入正确的手机号码,以便获取验证码！";
	$node->set_data($dtext);
    return;	
}

	  //$str="select did,cz,unix_timestamp(cz_time) as ctime from uu_member where mobile=\"".$tel."\" and uname=\"".$_SESSION["tmp_name"]."\" limit 1";
	  $str="select did,cz,unix_timestamp(cz_time) as ctime from uu_member where mobile=\"".$tel."\" limit 1";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $cz=$GLOBALS['le']->f("cz");
	  $ctime=$GLOBALS['le']->f("ctime");
	  $now=$_SERVER['REQUEST_TIME'];
	  if ($did){
		  if (($now-$ctime)<600){
			  $dtext.="0 | 10分钟内只能重置1次密码。\n请您稍后再来尝试！";
	          $node->set_data($dtext);
              return;
		  }elseif($cz>100){
			  $dtext.="0 | 已超过密码重置次数，不能重置！";
	          $node->set_data($dtext);
              return;			  
			  
		  }else{

 	require_once("../tel/tel.php");
	$_w['sms_pw']="31cfc170f70535b0d4dc92363c486de8";
	$randc=rand(100000,999999);
	//$sendmsg=$_SESSION["tmp_name"]."，您好！";
	$sendmsg="";
	$sendmsg.="这是先行网www.16u.com（一路游，好风景）密码重置验证码：".$randc."。";
	$sendmsg.="如果不是您本人重置，请删除本短信！";
    $url="http://gateway.woxp.cn:6630/utf8/web_api/?x_eid=10286&x_uid=Denny&x_pwd_md5=".$_w['sms_pw']."&x_ac=10&x_gate_id=300&x_target_no=".$tel."&x_memo=".$sendmsg; 
	$num=Get($url);
    if ($num<=0){
	 $dtext.="0 | ".telcode($num).$num;  
	}else{
	$dtext.="1 | 短信发送成功。\n可能需要1-10分钟，您才能收到验证码，请您耐心等候！";
	$_SESSION["pw_cz_randc"]=$randc;
	$_SESSION["tel_cz_randc"]=$tel;
	}
	          $node->set_data($dtext);
              return;				  	  
		  }
	  }else{
		$dtext.="0 | 找不到此手机号码的任何相关记录。\n请换个号码重试！";
	    $node->set_data($dtext);
        return;			  
	  }

	$node->set_data($dtext);
    return;		
}

function m_tel_second_ajax($tel){
	$node=$GLOBALS['cp']->add_node("m_tel_second_ajax_n");	
	$dtext="";

if(!preg_match('/^1(3|5|8)\d{9}$/ ',$tel)){
	$dtext.="0 | 请输入正确的手机号码,以便获取验证码！";
	$node->set_data($dtext);
    return;	
}

	  $str="select did from uu_member where mobile=\"".$tel."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  if (!$did){
 	require_once("../tel/tel.php");
	$_w['sms_pw']="31cfc170f70535b0d4dc92363c486de8";
	$randc=rand(100000,999999);
	$sendmsg="您好！";
	$sendmsg.="这是先行网www.16u.com（一路游，好风景）绑定手机验证码：".$randc."。";
	$sendmsg.="如果不是您本人绑定，请删除本短信！";
    $url="http://gateway.woxp.cn:6630/utf8/web_api/?x_eid=10286&x_uid=Denny&x_pwd_md5=".$_w['sms_pw']."&x_ac=10&x_gate_id=300&x_target_no=".$tel."&x_memo=".$sendmsg; 
	$num=Get($url);
    if ($num<=0){
	 $dtext.="0 | ".telcode($num).$num;  
	}else{
	$dtext.="1 | 短信发送成功。\n可能需要1-10分钟，您才能收到验证码，请您耐心等候！";
	$_SESSION["m_tel_randc"]=$randc;
	$_SESSION["mod_tel"]=$tel;
	}
	$node->set_data($dtext);
    return;				  	  

	  }else{
		$dtext.="0 | 此手机号已被使用。请换个号码重试！";
	    $node->set_data($dtext);
        return;			  
	  }

	$node->set_data($dtext);
    return;		
}

function user_login_ajax($user, $pw){
	$node=$GLOBALS['cp']->add_node("user_login_ajax_n");	
	$dtext="";

if (p_match($user)){
	$dtext.="0 | <img src='/images/3.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>用户名含有非法字符！</font>";
	$node->set_data($dtext);
    return;	
}

if (p_match($pw)){
	$dtext.="0 | <img src='/images/3.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>密码含有非法字符！</font>";
	$node->set_data($dtext);
    return;
}

$user=(string)$user;
if (strlen($user)==6 && $user{0}=='u') {
	  $str="select id,password from uu_biz_info where lcode='".$user."' order by id asc limit 1";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("id");
	  $password=$GLOBALS['le']->f("password");
	  $dlogin="xx";
	  $act='1';
	
}else{
//OK
	  $str="select m.did,m.password,m.dlogin,m.uname,m.act from uu_member m where (m.mobile=\"".$user."\" or m.email=\"".$user."\" or m.passport=\"".$user."\") and jz='0' limit 1";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $password=$GLOBALS['le']->f("password");
	  $dlogin=$GLOBALS['le']->f("dlogin");
	  $uname=$GLOBALS['le']->f("uname");
	  $act=$GLOBALS['le']->f("act");
}
	  
if (!$did){
	$dtext.="0 | <img src='/images/3.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>用户名错误！</font>";
	$node->set_data($dtext);
    return;	
}else{
if ($act!='1'){
	$dtext.="0 | <img src='/images/3.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>您的账户还未激活！不能登录！</font>";
	$node->set_data($dtext);
    return;
}

if ($password!=md5(md5($pw))){
	if ($dlogin>=6){
	   $dtext.="0 | <img src='/images/3.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>密码错误次数过多，你今天已法登录 ！</font>";
	   $node->set_data($dtext);
       return;	
      }elseif($dlogin!='xx'){
	   $str="update uu_member set dlogin=dlogin+1,dl_time=now() where did=".$did;
	   $GLOBALS['le']->query($str);
	   $dlogin++;
	   $dtext.="0 | <img src='/images/3.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>你还有".(6-$dlogin)."次的尝试机会，密码错误达到6次以上，您的账号将被冻结24小时！</font>";
	   $node->set_data($dtext);
       return;			  
	  }else{
	   $dtext.="0 | <img src='/images/3.png' class=imgie6 align='absmiddle'/>&nbsp;<font color=red>密码错误</font>";
	   $node->set_data($dtext);
       return;	  
	  }
	
}elseif($dlogin!='xx'){
	   $_SESSION["uu_user"]=$user;
	   $_SESSION["uu_id"]=$did;
	   
	   //更新登录时间
	  $str="update uu_member set last_time=now() where did='".$did."'";
      $GLOBALS['le']->query($str);
  
	   //$r=$_SESSION["uu_mid"]?2:1;
	   $r=1;
	   
	   $dtext.=$r."|".$user;
	   $node->set_data($dtext);
       return;	
}else{
	   $_SESSION["uu_mid"]=$user;
	   $r=2;
	   $dtext.=$r."|".$user;
	   $node->set_data($dtext);	
	
}


}
	$node->set_data($dtext);
    return;		
}

function m_email_sec_ajax($email) {
	$node=$GLOBALS['cp']->add_node("m_email_sec_ajaxn");
	$dtext="";
    $email=strtolower($email);
	if(!preg_match('/^\w+@([0-9]|[a-z]|[0-9a-z])+\.*([a-z]|[0-9]|[0-9a-z])+\.[a-z]{2,4}$/',$email)){
		$dtext.="0 | 邮件格式错误，请重填！";
		$node->set_data($dtext);
        return;	
	}

	  $str="select did,act from uu_member where email=\"".$email."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $act=$GLOBALS['le']->f("act");
	  $str="select did from uu_temp_member where date_add(mod_time,  interval 30 minute)>now() and email=\"".$email."\"";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did2=$GLOBALS['le']->f("did");	  
	  
	 if ($did || $did2){
		 if($act=='1'){
	      $dtext="0 | email地址已被使用，请更换！"; 
		 }else{
	      $dtext="0 | 此邮箱正在等待验证，无法注册！"; 	 
		 }
		$node->set_data($dtext);
        return;			 
	 }

    $host=$_SERVER['HTTP_HOST'];
	$str="insert uu_temp_member set uuid='".$_SESSION["uu_id"]."',email='$email',mod_time=now()";
    if (!$GLOBALS['le']->query($str)){
	   $dtext.="0 | 网络连接失败！稍后再试！";
	   $node->set_data($dtext);
       return;
    }
	
//发送邮件
   require_once("../mail_t/mail.php");
   $iden=md5($email);
   $res=mailt($email,"先行网账号绑定邮件",$host.",".$iden,"localhost,identify","../mail_t/content1.html");
   if ($res!=1){
	$dtext.=$res;
	$node->set_data($dtext);
    return;		
   }
    $dtext="1 |";
	$node->set_data($dtext);
    return;	
}

//邮件重置密码
function get_pw_email_ajax($email) {
	$node=$GLOBALS['cp']->add_node("get_pw_email_ajaxn");
	$dtext="";
    $email=strtolower($email);
	if(!preg_match('/^\w+@([0-9]|[a-z]|[0-9a-z])+\.*([a-z]|[0-9]|[0-9a-z])+\.[a-z]{2,4}$/',$email)){
		$dtext.="0 | 邮件格式错误，请重填！";
		$node->set_data($dtext);
        return;	
	}

	  $str="select did,act from uu_member where email=\"".$email."\" and act='1'";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  
	 if (!$did){
	    $dtext="0 | 此邮箱还未注册！"; 	 
		$node->set_data($dtext);
        return;			 
	 }

    $host=$_SERVER['HTTP_HOST'];
	
//发送邮件
   require_once("../mail_t/mail.php");
   $iden=md5($email);
   $res=mailt($email,"先行网账号密码重置邮件",$host.",".$iden,"localhost,identify","../mail_t/content_reset_pw.html");
   if ($res!=1){
	$dtext.=" 0 | 邮件发送失败".$res;
   }else{
    $dtext="1 | 邮件已发送，请注意查收。";
   }
	$node->set_data($dtext);
    return;	
}

function o_check_login_ajax($tel){
	$node=$GLOBALS['cp']->add_node("o_check_login_ajax_n");	
	$dtext="";
	
	//判定
	if ($_SESSION["uu_id"]) {
	$dtext.="0 |";
	$node->set_data($dtext);
    return;		
	}
	
	if(!preg_match('/^1(3|5|8)\d{9}$/ ',$tel)){
	$dtext.="0 |";
	$node->set_data($dtext);
    return;		
    }
	
	$str="select did from uu_member where mobile='".htmlspecialchars($tel)."'";
    $GLOBALS['le']->query($str);
    $GLOBALS['le']->fetch_assoc();
    $did=$GLOBALS['le']->f("did");
	
	if ($did) {
	$dtext.="1 |".$did;
	}else{
	$dtext.="0 |";	
	}

	$node->set_data($dtext);
    return;		
}

function o_login_ajax($user, $pw){
	$node=$GLOBALS['cp']->add_node("o_login_ajax_n");	
	$dtext="";
if (p_match($user)){
	$dtext.="0 | 用户名含有非法字符！";
	$node->set_data($dtext);
    return;	
}

if (p_match($pw)){
	$dtext.="0 | 密码含有非法字符！";
	$node->set_data($dtext);
    return;	
}

	  $str="select did,password,dlogin,uname,act,cname,mobile,cmobile,onsale,money from uu_member where (mobile=\"".$user."\" or email=\"".$user."\" or passport=\"".$user."\") and jz='0' limit 1";
      $GLOBALS['le']->query($str);
      $GLOBALS['le']->fetch_assoc();
      $did=$GLOBALS['le']->f("did");
	  $password=$GLOBALS['le']->f("password");
	  $dlogin=$GLOBALS['le']->f("dlogin");
	  $uname=$GLOBALS['le']->f("uname");
	  $act=$GLOBALS['le']->f("act");
	  $cname=$GLOBALS['le']->f("cname");
	  $mobile=$GLOBALS['le']->f("mobile");
	  $cmobile=$GLOBALS['le']->f("cmobile");
	  $onsale=$GLOBALS['le']->f("onsale");
	  $money=$GLOBALS['le']->f("money");
	  
if ($act!='1'){
	$dtext.="0 | 您的账户还未激活！不能登录！";
	$node->set_data($dtext);
    return;
}

if ($password!=md5(md5($pw))){
	if ($dlogin>=6){
	   $dtext.="0 | 密码错误次数过多，你今天已法登录 ！";
	   $node->set_data($dtext);
       return;	
      }else{
	   $str="update uu_member set dlogin=dlogin+1,dl_time=now() where did=".$did;
	   $GLOBALS['le']->query($str);
	   $dlogin++;
	   $dtext.="0 | 密码错误，你还有".(6-$dlogin)."次的尝试机会，达到6次以上，您的账号将被冻结24小时！";
	   $node->set_data($dtext);
       return;			  
	  }
	
}else{
	   $_SESSION["uu_user"]=$mobile;
	   $_SESSION["uu_id"]=$did;
	   
	   //更新登录时间
	  $str="update uu_member set last_time=now() where did='".$did."'";
      $GLOBALS['le']->query($str);
	  
	  $v=$uname?$uname:"";
      $v=$cname?$cname:$v;
	  $vtel=$mobile?$mobile:"";
	  $vtel=$cmobile?$mobile:$vtel;
	  
	  $dtext.="1|".$v."|".$vtel."|".$onsale."|".$money;
	  $node->set_data($dtext);
      return;	
}

	$node->set_data($dtext);
    return;		
}

function o_yhq_login_ajax(){
	$node=$GLOBALS['cp']->add_node("o_yhq_login_ajax_n");	
	$dtext="";
	
	if ($_SESSION["uu_user"]) $dtext.="0 |";
	else $dtext.="1 |";
	$node->set_data($dtext);
	return;
}

function u_example(){
	$node=$GLOBALS['cp']->add_node("u_example_n");	
	$dtext="";

	$node->set_data($dtext);
    return;		
}

$cp->register("mailreg");
$cp->register("pwdreg");
$cp->register("checkscheck");
$cp->register("reg_now_ajax");
$cp->register("re_send_check_mail_ajax");
$cp->register("checktel_ajax");
$cp->register("get_yzm_ajax");
$cp->register("forget_pw_ajax");
$cp->register("chkTrueName_ajax");
$cp->register("get_pw_sms_ajax");
$cp->register("user_login_ajax");
$cp->register("m_tel_first_ajax");
$cp->register("m_tel_second_ajax");
$cp->register("m_tel_third_ajax");
$cp->register("m_email_sec_ajax");
$cp->register("o_check_login_ajax");
$cp->register("o_login_ajax");
$cp->register("o_yhq_login_ajax");
$cp->register("get_pw_email_ajax");

$cp->start();
$cp->return_data();
?>